public class Solution1138 {
    public String alphabetBoardPath(String target) {
        int last=0;
        StringBuilder stringBuilder=new StringBuilder();
        for (char c : target.toCharArray()) {
            stringBuilder.append(deal(last,c-'a'));
            last=c-'a';
        }
        return stringBuilder.toString();
    }

    private String deal(int a, int b) {
        StringBuilder stringBuilder=new StringBuilder();
        while (a/5>b/5){
            stringBuilder.append('U');
            a-=5;
        }
        while (a%5>b%5){
            stringBuilder.append('L');
            a--;
        }
        while (a%5<b%5){
            stringBuilder.append('R');
            a++;
        }
        while (a/5<b/5){
            stringBuilder.append('D');
            a+=5;
        }
        stringBuilder.append('!');
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Solution1138().alphabetBoardPath("leet"));
    }
}
